<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/5/16
 * Time: 15:03
 */
include '../classes/logincheck.php';
include '../classes/conn.php';
if(!islogin()=='stu_login') {
    die('error');
}

$homework=$_POST['homework'];
$student=$_SESSION['stu_num'];

//查询班级号
$queryClass="select class from homework where Id='{$homework}'";
$res=mysql_query($queryClass);
$row=mysql_fetch_assoc($res);
$class=$row['class'];

//查询教师号
$queryTeacher="select teacher from class where num='{$class}'";
$res=mysql_query($queryTeacher);
$row=mysql_fetch_assoc($res);
$teacher=$row['teacher'];

$time=$_POST['time'];

$query="insert into submit (homework, student, class, time) values ('{$homework}','{$student}',{$class},'{$time}')";
mysql_query($query);
$id=mysql_insert_id();

if(is_uploaded_file($_FILES['up-homeworkfile']['tmp_name'])){

    $file=$_FILES['up-homeworkfile']['name'];
    $dotindex=strrpos($file,'.');//最后一次‘.’出现的位置
    $sufname=substr($file,$dotindex+1);//
    $file=$id.'.'.$sufname;

    move_uploaded_file($_FILES['up-homeworkfile']['tmp_name'],
        "../Files/" .$teacher."/homework/submit/submit_".$student.$file);
    $attach="requests/Files/" .$teacher. "/homework/submit/submit_".$student.$file;

    $query="update submit set attach='{$attach}' where Id='{$id}'";
    mysql_query($query);
    echo '1';

}
else die('nofile');